<template>
  <el-container class="layout-container-demo" style="height: 100vh">
    <Menus></Menus>

    <el-container>
      <el-header style="text-align: right; font-size: 18px">
        <div class="toolbar">
          <el-dropdown>
            <el-icon style="margin-right: 8px; margin-top: 1px;font-size: 18px;">
              <setting />
            </el-icon>
            <template #dropdown>
              <el-dropdown-menu>
                <el-dropdown-item>
                  首页
                </el-dropdown-item>

                <el-dropdown-item divided @click="logout">
                  <span style="display:block;">退出登录</span>
                </el-dropdown-item>
              </el-dropdown-menu>
            </template>
          </el-dropdown>
          <span>{{ userStore.userinfo.userName }}</span>
        </div>
      </el-header>

      <el-main>
        <!-- 面包屑导航 -->
        <el-card>
          <el-breadcrumb separator="/">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <template v-for="(item, index) in route.matched" :key="index">
              <el-breadcrumb-item v-if="item.path !== '/' && item.path !== '/home'">
                <router-link :to="item.path">{{ item.meta.title}}</router-link>
              </el-breadcrumb-item>
            </template>
          </el-breadcrumb>
        </el-card>
        <!-- 主内容显示区域 -->
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>
  
<script setup>
import { useRoute, useRouter } from 'vue-router'
import { useUserInfo } from '../store';
import { ElMessage, ElMessageBox } from 'element-plus'
import Menus from './Menus.vue'

const userStore = useUserInfo()
const route = useRoute()
const router = useRouter()

//  退出登录
const logout = () => {
  ElMessageBox.confirm(
    '您确定退出当前登录的账号吗?',
    '系统提示',
    {
      confirmButtonText: '确定',
      cancelButtonText: '取消',
      type: 'warning',
    }
  )
    .then(() => {
      // 清除用户token信息
      localStorage.removeItem('member_token')
      // 跳转至登录页面
      router.push('/login')
    })
    .catch(() => {
    })
}

</script>
  
<style>
.layout-container-demo .el-header {
  position: relative;
  background-color: rgb(241, 241, 241);
  color: var(--el-text-color-primary);
  box-shadow: inset 0 -5px 10px rgb(200, 200, 200);
}

.layout-container-demo .el-aside {
  color: var(--el-text-color-primary);
  background: #545c64;
}

.layout-container-demo .el-menu {
  border-right: none;
}

.layout-container-demo .el-main {
  padding: 0;
}

.layout-container-demo .toolbar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  right: 20px;
}
</style>
  